package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.pojo.Process;
import com.example.pojo.ProcessNode;
import com.example.mapper.ProcessNodeMapper;
import com.example.service.IProcessNodeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.vo.ResultVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * <p>
 * 流程节点表 服务实现类
 * </p>
 *
 * @author wsl
 * @since 2022-04-11
 */
@Service
public class ProcessNodeServiceImpl extends ServiceImpl<ProcessNodeMapper, ProcessNode> implements IProcessNodeService {

    @Override
    @Transactional
    public ResultVo addProcessNodes(Process process) {
        Integer processId = process.getId();
        List<ProcessNode> processNodeList = process.getProcessNodeList();
        //1。删除流程所有节点
        baseMapper.deleteNodesByProcessId(processId);
        //2.替换新的流程节点
        processNodeList.forEach(node->{
            node.setProcessId(processId);
            baseMapper.insert(node);
        });
        return ResultVo.ok("更新成功");
    }

    @Override
    public ResultVo getProNodesByProId(Integer processId) {
        List<ProcessNode> node = baseMapper.selectProNodesByProId(processId);
        return ResultVo.response(node);
    }
}
